package com.example.study.controller;

import com.example.study.dao.Blogger;
import com.example.study.dao.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * author xll
 */
@Controller
@RequestMapping(value = "/thymeleaf")
public class PageController {


    @RequestMapping("/test404")
    public String test404() {
        return "index";
    }

    @RequestMapping("/test500")
    public String test500() {
        int i = 1 / 0;
        return "index";
    }

    @RequestMapping(value = "/index")
    public String index(){
        return "index";
    }

    @GetMapping("/getBlogger")
    public String getBlogger(Model model) {
        Blogger blogger = new Blogger(1L, "xll", "123456");
        model.addAttribute("blogger", blogger);
        return "blogger";
    }

    @GetMapping("/getBloggerList")
    public String getBloggerList(Model model) {
        List<Blogger> userList = new ArrayList<>();
        Blogger blogger = new Blogger(2L,"xll","123");
        Blogger blogger1 = new Blogger(3L,"lcy","234");
        userList.add(blogger);
        userList.add(blogger1);
        model.addAttribute("userList",userList);
        return "bloggerList";
    }
}
